package module

import "sync/atomic"

type fakeModule struct {
	mid MID

	score uint64

	count uint64

	scoreCalculator CalculateScore
}

func (fm *fakeModule) ID() MID {
	return fm.mid
}

func (fm *fakeModule) Addr() string {
	parts, err := SplitMID(fm.mid)
	if err == nil {
		return parts[2]
	}
	return ""
}

func (fm *fakeModule) Score() uint64 {
	return atomic.LoadUint64(&fm.score)
}

func (fm *fakeModule) SetScore(score uint64) {
	atomic.StoreUint64(&fm.score, score)
}

func (fm *fakeModule) ScoreCalculator() CalculateScore {
	return fm.scoreCalculator
}

func (fm *fakeModule) CalledCount() uint64 {
	return fm.count + 10
}

func (fm *fakeModule) AcceptedCount() uint64 {
	return fm.count + 8
}

func (fm *fakeModule) CompletedCount() uint64 {
	return fm.count + 6
}

func (fm *fakeModule) HandlingNumber() uint64 {
	return fm.count + 2
}

func (fm *fakeModule) Counts() Counts {
	return Counts{
		fm.CalledCount(),
		fm.AcceptedCount(),
		fm.CompletedCount(),
		fm.HandlingNumber(),
	}
}

func (fm *fakeModule) Summary() SummaryStruct {
	return SummaryStruct{}
}

func NewFakeAnalyzer(mid MID, scoreCalculator CalculateScore) Analyzer {
	return &fakeAnalyzer{
		fakeModule: fakeModule{
			mid:             mid,
			scoreCalculator: scoreCalculator,
		},
	}
}

type fakeAnalyzer struct {
	fakeModule
}

func (analyzer *fakeAnalyzer) RespParsers() []ParseResponse {
	return nil
}

func (analyzer *fakeAnalyzer) Analyze(resp *Response) (dataList []Data, errorList []error) {
	return
}
